<!doctype html>
<html>
<head>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
</head>
<body>
<p> Verify that a timeout ProgressEvent is dispatched and have the expected values.</p>
<div id="log"></div>
<script type="text/javascript">

function verifyProgressEvent(context, e)
{
    assert_true(e.loaded >= 0, "Non-zero 'loaded' value for '" + context + "' event.");
    assert_true(!e.lengthComputable || e.total > 0, "Non-zero 'total' value for '" + context + "' event.");
}

function logProgressEvent(e) {
    results += " " + e.type;
}

function unexpectedProgressEvent(e) {
    assert_unreached("Unexpected request error");
}

function timeoutHandler(e)
{
    assert_true(e instanceof ProgressEvent);
    verifyProgressEvent("ontimeout", e);
    testOnTimeoutEvent.done();
}

var testOnTimeoutEvent = async_test("Check that 'timeout' events are delivered and have expected values.");
testOnTimeoutEvent.step(function () {
    var xhr = new XMLHttpRequest();
    xhr.ontimeout = testOnTimeoutEvent.step_func(timeoutHandler);
    xhr.onabort = testOnTimeoutEvent.step_func(unexpectedProgressEvent);
    xhr.onerror = testOnTimeoutEvent.step_func(unexpectedProgressEvent);
    xhr.onload = testOnTimeoutEvent.step_func(unexpectedProgressEvent);
    xhr.timeout = 30;
    xhr.open("GET", "/resources/load-and-stall.php?name=../resources/test.mp4&stallAt=100&stallFor=10000&mimeType=video/mp4", true);
    xhr.send();
});
</script>
</body>
</html>
